﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace stringconversions
{
    public class StringConversionsEBC
    {
        public static Dictionary<string, string> ToDictionary(string configuration)
        {
            Dictionary<string, string> dict = null;

            In_SplitConfiguration(
               new Configuration{Settings = configuration}, settings => 
               In_MapSettings(settings, pvPairs => 
               In_CreateDictionary(pvPairs, d => 
               dict = d)));

            return dict;
        }


        internal static void In_SplitConfiguration(Configuration config, Action<IEnumerable<Setting>> Out_Settings)
        {
            Out_Settings(StringConversions.SplitConfigIntoSettings(config));
        }

        internal static void In_MapSettings(IEnumerable<Setting> settings, Action<IEnumerable<Tuple<Parameter, Value>>> Out_PVPairs)
        {
            Out_PVPairs(StringConversions.SplitSettingsIntoParamValuePairs(settings));
        }

        internal static void In_CreateDictionary(IEnumerable<Tuple<Parameter, Value>> pvPairs, Action<Dictionary<string, string>> Out_Dictionary)
        {
            Out_Dictionary(StringConversions.CreateDictionary(pvPairs));
        }
    }
}
